package com.letoo.sso.core.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.letoo.sso.common.domain.ContextConstants;
import com.letoo.sso.common.utils.AssertUtil;
import com.letoo.sso.core.service.AdminService;
import com.letoo.sso.dataaccess.dao.cahce.AppBaseConfigCacheDAO;
import com.letoo.sso.dataaccess.dao.db.AppBaseConfigDBDAO;
import com.letoo.sso.dataaccess.domain.dbo.AppBaseConfigDO;

/**
 * AdminService接口实现
 * 
 * @author: dengjie
 */
@Service("adminService")
public class AdminServiceImpl implements AdminService {

  @Resource
  private AppBaseConfigDBDAO appBaseConfigDBDAO;

  @Resource
  private AppBaseConfigCacheDAO appBaseConfigCacheDAO;

  @Override
  public void initAppBaseConfigToCache(int appId) {
    AssertUtil.gt(appId, 0, "appTypeId must gt zero");
    List<AppBaseConfigDO> appBaseConfigDOs = appBaseConfigDBDAO.queryAppConfigByAppId(appId);
    AssertUtil.notEmpty(appBaseConfigDOs, "the configs collections is empty");
    //
    appBaseConfigCacheDAO.setAppBaseConfig(ContextConstants.APP_ID, appBaseConfigDOs);
  }
}
